package com.hq.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hq.entity.QuestionType;
import com.hq.entity.Score;
import com.hq.entity.ScoreVO;
import com.hq.mapper.ScoreMapper;
import com.hq.service.ScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("scoreService")
@Slf4j
public class ScoreServiceImpl implements ScoreService {

    //批量删除
    @Override
    public int delScores(String ids) {
        log.info("批量删除的题型id{}",ids);
        return scoreMapper.delScores(ids);
    }

    //修改
    @Override
    public int editScore(ScoreVO scorevo) {
        log.info("修改的分数{}",scorevo);
        return scoreMapper.editScore(scorevo);
    }

    //单行删除
    @Override
    public int delScore(int id) {
        log.info("删除的题型id{}",id);
        return scoreMapper.delScore(id);
    }

    @Autowired
    private ScoreMapper scoreMapper;

    //分页查询
    @Override
    public Map<String, Object> findByPage(int page, int size) {
        log.info("分页查询的参数page{},size{}",page,size);
        Map<String,Object> map=new HashMap<>();
        Page<Object> objects = PageHelper.startPage(page, size);
        List<ScoreVO> list = scoreMapper.findAll();
        map.put("list",list);
        map.put("total",objects.getTotal());
        return map;
    }


    //交卷
    @Override
    public int add(Score score) {
        log.info("交卷的参数{}",score);
        return scoreMapper.add(score);
    }
}
